import { DashboardMetricConfig } from '@redfire/shared-types';

/**
 * 仪表盘指标配置
 * 通过修改此配置文件来调整仪表盘显示的指标
 */
export const dashboardMetrics: DashboardMetricConfig[] = [
  {
    id: 'shanghai_index',
    position: 1,
    type: 'market_index',
    indexCode: '000001.SH',
    displayName: '上证指数',
    apiEndpoint: '/api/v1/market/index',
    updateInterval: 5000,
    showChange: true,
    showTrend: true,
    dataSource: 'tushare',
    enabled: true
  },
  {
    id: 'chinext_index',
    position: 2,
    type: 'market_index',
    indexCode: '399006.SZ',
    displayName: '创业板指数',
    apiEndpoint: '/api/v1/market/index',
    updateInterval: 5000,
    showChange: true,
    showTrend: true,
    dataSource: 'tushare',
    enabled: true
  },
  {
    id: 'shenzhen_index',
    position: 3,
    type: 'market_index',
    indexCode: '399001.SZ',
    displayName: '深证成指',
    apiEndpoint: '/api/v1/market/index',
    updateInterval: 5000,
    showChange: true,
    showTrend: true,
    dataSource: 'tushare',
    enabled: true
  },
  {
    id: 'hsi_index',
    position: 4,
    type: 'market_index',
    indexCode: 'HSI',
    displayName: '恒生指数',
    apiEndpoint: '/api/v1/market/index',
    updateInterval: 5000,
    showChange: true,
    showTrend: true,
    dataSource: 'tushare',
    enabled: true
  }
];

/**
 * 获取启用的指标配置
 */
export const getEnabledMetrics = (): DashboardMetricConfig[] => {
  return dashboardMetrics
    .filter(metric => metric.enabled !== false)
    .sort((a, b) => a.position - b.position);
};

/**
 * 根据ID获取指标配置
 */
export const getMetricById = (id: string): DashboardMetricConfig | undefined => {
  return dashboardMetrics.find(metric => metric.id === id);
};

/**
 * 根据类型获取指标配置
 */
export const getMetricsByType = (type: DashboardMetricConfig['type']): DashboardMetricConfig[] => {
  return dashboardMetrics.filter(metric => metric.type === type && metric.enabled !== false);
};
